async function runCodes(){
//this code its gonna run async
ajaxCall().then((response)=>{
if(response){
//true
} else {
//false
}
});
//some other codes
}
function ajaxCall(){
return new Promise((resolve) => {
$.ajax({
url: '/controller.php',
type: 'GET',
dataType: "json",
data: {
action: "loadPageContent"
},
success: function(retour) {
localStorage.removeItem('myhtml');
if(retour.status && retour.htmlDatas){
storedDatas["posts"] = retour.htmlDatas;
storedDatas["date_scrapping"] = retour.date_scrapping;
localStorage.setItem("myhtml", JSON.stringify(storedDatas) ); // ¨Pour si relance
$('#container').html(retour.htmlDatas);
resolve(true);
}
else {
alert('error');
resolve(false);
}
},
error: function(retour) {
alert('error');
resolve(false);
},
});
});
}